///*
// * @(#)PayServiceCallbackListener.java 创建于 2016-07-16 13:32:03
// *
// * 版权：版权所有 Bsoft 保留所有权力。
// */
//package hcn.ods.pay.diagnosis;
//
//import com.security.cipher.sm.SM4Utils;
//import ctd.account.AccountCenter;
//import ctd.dictionary.Dictionary;
//import ctd.dictionary.DictionaryController;
//import hcn.base.pay.TradeType;
//import hcn.base.pay.event.PayEvent;
//import hcn.base.pay.event.PayEventListener;
//import hcn.base.register.ISmsService;
//import hcn.bean.PushMessageBean;
//import hcn.enums.MsgServiceTypeEnum;
//import hcn.enums.MsgTemplateCode;
//import hcn.ods.PayTrade;
//import hcn.util.BaseResponse;
//import hcn.service.base.sendMsg.IMessageSyncService;
//import hcn.util.ResultCode;
//import org.apache.commons.lang3.time.DateFormatUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import pcn.enums.RoleIdEnum;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @author <a href="mailto:chinnsii@163.com">zhengshi</a>
// */
//public class PayServiceCallbackListener implements PayEventListener {
//    private static Logger logger = LoggerFactory.getLogger(PayServiceCallbackListener.class);
//
//    private ISmsService smsService;
//    @Autowired
//    private IMessageSyncService messageSyncService;
//
//    /**
//     *
//     * @param event
//     * @throws Exception
//     */
//    @Override
//    public void notify(PayEvent event) throws Exception {
//        PayTrade payTrade = event.getPayTrade();
//        if (TradeType.getTradeType(payTrade.getTradeType()) == TradeType.diagnosisFee) {// @@ 诊间支付
//            String userId = payTrade.getUserId();
//            //国产化加密算法存储 解密
//            String phoneNo = SM4Utils.decryptData_ECB(AccountCenter.getUser(userId).getLoginName());
//            //发送短信（smsService.asyncSendSms）
//            PushMessageBean pushMessageBean=new PushMessageBean();
//            pushMessageBean.setRoleId(RoleIdEnum.PATIENT.title());
//            pushMessageBean.setMsgServiceType(MsgServiceTypeEnum.SMSSERVICE_ASYNCSENDSMS.getCode());
//            pushMessageBean.setUserId(userId);
//            pushMessageBean.setMobile(phoneNo);
//            if (event.getStatus() == PayEvent.TradeStatus.SUCCESS) {
//                String time = DateFormatUtils.format(payTrade.getFinishTime(), "yyyy-MM-dd HH:mm:ss");
//                Dictionary dic = DictionaryController.instance().get("hcn.base.dictionary.organization");
//                pushMessageBean.setTemplateCode(MsgTemplateCode.HOSPITALPAYSUCCESS.getCode());
//
//                Map<String,String> variableMap=new HashMap<String, String>();
//                variableMap.put("#医院名称#",dic.getText(payTrade.getOrgId()));
//                variableMap.put("#支付类型#",event.getPayType().getDisplay());
//                variableMap.put("#支付金额#",String.format("%.2f", payTrade.getTotalFee()));
//                variableMap.put("#时间#",time);
//                pushMessageBean.setMsgVariableMap(variableMap);
//            } else {
//                pushMessageBean.setTemplateCode(MsgTemplateCode.HOSPITALPAYFAIL.getCode());
//            }
//            BaseResponse baseResponse = messageSyncService.productionMessage(pushMessageBean);
//            if(ResultCode.SUCCESS!=baseResponse.getCode()){
//                logger.error(baseResponse.getMessage());
//            }
//        }
//    }
//
//    public ISmsService getSmsService() {
//        return smsService;
//    }
//
//    public void setSmsService(ISmsService smsService) {
//        this.smsService = smsService;
//    }
//}
